var iconPath = "icons/";
var USELOG = false;

////////////////////////////////////////////////////////////////////////////////////
function init() {
	
	var args = getArgs();
	if (args.category) {
		g_category = args.category;
	}
	initMap();

	var dataArrayLen = markers.length;
	writeLog(dataArrayLen);
	for(i=0; i<dataArrayLen; i++) {	
		addMarker(markers[i].latitude, markers[i].longitude, markers[i].name, markers[i].url, markers[i].userid, markers[i].add_date, markers[i].row_seq_no);
		writeLog(markers[i].latitude);
	}

	handleResize();
}

/////////////////////////////////////////////////////////////////////////////////////
// This should be removed from production code ... but it is very useful
/////////////////////////////////////////////////////////////////////////////////////
function writeLog(message) {
	if (USELOG) {
		GLog.write(message);	
	};
}



//////////////////////////////////////////////////////////////////////////////////////
function addMarker(latitude, longitude, description, url, userid, add_date, row_seq_no) {
	
	var theDesc = "Added by: " + userid + " - on: " + add_date;
	var thePoint = new GLatLng(latitude, longitude);
	var marker = new GMarker(thePoint);
	
  	GEvent.addListener(marker, 'click', function() { confirmRow(userid, description, url, row_seq_no);} );
  
	GEvent.addListener(marker,'mouseover',function() {
		marker.openToolTip(theDesc);
	});

	GEvent.addListener(marker,'mouseout',function() {
		marker.closeToolTip();
	});

	if (description != "") {		
		makebox(thePoint, description);
	}
  
	map.addOverlay(marker);
}


////////////////////////////////////////////////////////////////////////////////
function confirmRow(userid, description, url, row_seq_no) {
	//GLog.write(row_seq_no);
	var myStr = new String;
	myStr = row_seq_no;
	document.getElementById('frm_userid').value = userid;
	document.getElementById('frm_label').value = description;
	document.getElementById('frm_link').value = url;
	document.getElementById('frm_row_seq_no').value = myStr;

}


////////////////////////////////////////////////////////////////////////////////
function deleteRow() {

	rowToDelete = document.getElementById('frm_row_seq_no').value;
	GDownloadUrl('../shared_v2/mapblog_data_delete.php?row=' + rowToDelete, function(data, responseCode) {
		if (data == 1) {
			alert("The point you selected was deleted. It will be removed from the map on the next refresh.");
		} else {
			alert("Some problem has occured. Please try again. ");
		}
				
			
	});
}

window.onresize = handleResize;
window.onload = init;
